using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.IO;

using ExchangeHog.Pop3Client.Responses;

namespace ExchangeHog.Pop3Client.Commands
{
	internal sealed class RetrCommand : Pop3Command<RetrResponse>
	{
		int message;

		public RetrCommand(Stream stream, int message)
			: base(stream, true, Pop3State.Transaction)
		{
			if (message < 0)
				throw new ArgumentOutOfRangeException("message");

			this.message = message;
		}

		protected override byte[] CreateRequestMessage()
		{
			return GetRequestMessage(Pop3Commands.Retr, message.ToString(), Pop3Commands.Crlf);
		}

		protected override RetrResponse CreateResponse(byte[] buffer)
		{
			Pop3Response response = Pop3Response.CreateResponse(buffer);
			return new RetrResponse(response, GetResponseLines(StripPop3HostMessage(buffer, response.HostMessage)));
		}
	}
}
